# 部署到 Gitee Pages 脚本 (PowerShell)

Write-Host "🚀 开始部署到 Gitee Pages..." -ForegroundColor Green

# 1. 构建项目
Write-Host "📦 构建项目..." -ForegroundColor Yellow
npm run build

if ($LASTEXITCODE -ne 0) {
    Write-Host "❌ 构建失败，请检查错误信息" -ForegroundColor Red
    exit 1
}

Write-Host "✅ 构建成功" -ForegroundColor Green

# 2. 检查 dist 目录是否存在
if (-not (Test-Path "dist")) {
    Write-Host "❌ dist 目录不存在，构建可能失败" -ForegroundColor Red
    exit 1
}

# 3. 添加构建文件到 git
Write-Host "📝 添加构建文件到 git..." -ForegroundColor Yellow
git add dist -f

# 4. 检查是否有变更
$status = git status --porcelain
if ($status -match "dist/") {
    # 5. 提交构建文件
    Write-Host "💾 提交构建文件..." -ForegroundColor Yellow
    $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    git commit -m "build: 更新生产构建文件 $timestamp"
    
    # 6. 推送到远程仓库
    Write-Host "📤 推送到远程仓库..." -ForegroundColor Yellow
    git push origin main
    
    if ($LASTEXITCODE -eq 0) {
        Write-Host "✅ 部署完成！" -ForegroundColor Green
        Write-Host "🌐 请访问 Gitee Pages 查看您的应用" -ForegroundColor Cyan
        Write-Host "📋 记得在 Gitee 仓库中启用 Pages 服务" -ForegroundColor Cyan
    } else {
        Write-Host "❌ 推送失败，请检查网络连接和权限" -ForegroundColor Red
        exit 1
    }
} else {
    Write-Host "ℹ️  没有新的构建文件需要提交" -ForegroundColor Blue
}

Write-Host "🎉 部署流程完成！" -ForegroundColor Green
